package com.hmall.item.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    //分页查询商品
    @GetMapping("/list")
    public PageDTO<Item> page(@RequestParam Integer page,Integer size){
        IPage<Item> itemIPage= itemService.selectpage(page,size);
        PageDTO<Item> itemPageDTO = new PageDTO<>(itemIPage.getTotal(), itemIPage.getRecords());
        return itemPageDTO;
    }

    //根据id查询商品
    @GetMapping("{id}")
    public Item getById(@PathVariable Long id){
        return itemService.getById(id);
    }

    //新增商品
    @PostMapping
    public void save(@RequestBody Item item){
         itemService.save(item);
    }
}
